package com.knight.spring.aop.advisor;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;

public class XmlAspect {

    public void before(JoinPoint joinPoint){
        System.out.println("before "+joinPoint);
    }

    public void after(JoinPoint joinPoint){
        System.out.println("after " + joinPoint);
    }

    public void around(JoinPoint joinPoint){
        long start = System.currentTimeMillis();
        try {
            ((ProceedingJoinPoint) joinPoint).proceed();
            long end = System.currentTimeMillis();
            System.out.println("around " + joinPoint + "\tUse time : " + (end - start) + " ms!");
        } catch (Throwable e) {
            long end = System.currentTimeMillis();
            System.out.println("around " + joinPoint + "\tUse time : " + (end - start) + " ms with exception : " + e.getMessage());
        }
    }

    public void afterReturn(JoinPoint joinPoint){
        System.out.println("afterReturn " + joinPoint);
    }

    public void afterThrow(JoinPoint joinPoint, Exception ex){
        System.out.println("afterThrow " + joinPoint + "\t" + ex.getMessage());
    }
}
